#include "header.h"

void recvfile(int connfd, FILE *fp, int size)
{
	int ret;
	char *buf = NULL;

	buf = (char *) malloc(MAX_PKT_SIZE+1);

	while (size > 0) {

		ret = recv(connfd, buf, MAX_PKT_SIZE, 0);
		if (FAILURE == ret) {
			printf("unable to recv data from client\n");
			free(buf);
			goto end;
		}

		size = size-ret;
		fwrite(buf, ret, 1, fp);
	}

	free(buf);

end:
	return;
}

